﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FamilyTree
{
    public partial class MemberCheck : Form
    {
        public MemberCheck()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string connString = @"Data Source = PC-20190806MQPW\SQLEXPRESS01; Initial Catalog = 终极电子族谱; User ID = sa; Password = 123456"; //数据库连接
            string id = textBoxID.Text;
         
            SqlConnection conn = new SqlConnection(connString);
            conn.Open();
            string sql = @"SELECT * FROM member WHERE id='" + textBoxID.Text + "'";
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataReader dr = cmd.ExecuteReader();
            if (!dr.Read())
            {
                MessageBox.Show(id + "号用户不存在！");
                return;
            }
            textBox1.Text = dr["name"].ToString();
            textBox2.Text = dr["sex"].ToString();
            textBox3.Text = dr["birthday"].ToString();
            textBox4.Text = dr["address"].ToString();
            textBox5.Text = dr["dad"].ToString();
            textBox6.Text = dr["mom"].ToString();
            textBox7.Text = dr["zibei"].ToString();
            textBox8.Text = dr["tree"].ToString();
            if (textBoxID.Text == "01")
            {
                textBox9.Text = "为人民服务";
                textBox10.Text = "为家族争光！";
            }
            else if (textBoxID.Text == "02")
            {
                textBox9.Text = "为祖国加油";
                textBox10.Text = "为民族争气";
            }
            conn.Close();
        }

        private void MemberCheck_Load(object sender, EventArgs e)
        {

        }

        private void textBox8_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox9_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
